//
//  WDCardManager.m
//  WDPolymerizeSDK
//
//  Created by little People on 2023/6/6.
//

#import "WDCardManager.h"
#import "WDJsonManager.h"
#import "WDNSLog.h"
@implementation WDCardManager

+ (void)WDGetCardJsonWithAppName:(NSString *)appName completionHandler:(void (^)(BOOL isSuccess, WDCardModel *model))completionHandler
{
    NSString *string = [NSString stringWithFormat:@"https://static.zuiqiangyingyu.cn/wb_webview/wsdk_source/config/%@.json",[WDJsonManager requestAppNameForSDKConfigFile]];
    //1.创建URL对象
    NSURL *url = [NSURL URLWithString:string];
    //2.建立会话 session支持三种类型的任务
    //    NSURLSessionDataTask  //加载数据
    //    NSURLSessionDownloadTask  //下载
    //    NSURLSessionUploadTask   //上传
    NSURLSession *session = [NSURLSession sharedSession];
    //3.创建请求任务，（该方法内部默认使用get）直接进行传递url即可
    NSURLSessionDataTask *dataTask = [session dataTaskWithURL:url completionHandler:^(NSData * _Nullable data, NSURLResponse * _Nullable response, NSError * _Nullable error) {
        //data就是你获取到的数据，你可以自行对其进行解析
        //error就是获取失败时出现的问题
        if (error)
        {
            completionHandler(NO,nil);
        }
        else
        {
            NSDictionary *content = [NSJSONSerialization JSONObjectWithData:data options:NSJSONReadingMutableContainers error:nil];//转换数据格式
            
            WDLog(@"content---: %@", content);
            
            if (content)
            {
                WDCardModel *model = [WDCardModel shareCardModel];
                
                model.hasCardContent = YES;
                model.adPrivacy = [content objectForKey:@"adPrivacy"];
                model.adCustomList = [content objectForKey:@"adCustomList"];
                
                completionHandler(YES,model);
            }
        }
        
    }];
    //4.启动任务
    [dataTask resume];
}



@end
